using System;
using System.Text;
using System.Collections.Generic;

namespace Demo_G.O.S.E.ServerEngine.AIEngine.Agent
{

/**
 * This class is used to load the XML-based configuration for the Daemon.
 */
    public class DaemonConfig
    {

        /** The port to use. */
        private int port = 0;

        /** The log to use. */
        private String log = null;

        /** The verbosity flag. */
        private bool verbose = false;

        /** The remote classloading flag. */
        private bool remoteClassLoading = true;

        /** The list of allowed hosts. */
        //private Vector allowed = new Vector();

        /** The list of denied hosts. */
        //private Vector denied = new Vector();

        /** The list of agents to start up. */
        //private Vector agents = new Vector();

        /** The list of services to start up. */
        //private Vector services = new Vector();

        /** The original document that the configuration was built from. */
        //private Document doc = null;

        /**
         * Constructs a new DaemonConfig.
         *
         * @param doc The Document object to construct the DaemonConfig from.
         */
        //private DaemonConfig(Document doc)
        //{
        //this.doc = doc;

        //Element daemon = doc.getDocumentElement();
        //if(daemon.getTagName().equals("daemon")) {
        //    // Get the port if specified.
        //    try {
        //    this.port = Integer.parseInt(daemon.getAttribute("port"));
        //    } catch(NumberFormatException nfe) {
        //    System.err.println(nfe);
        //    } catch(NullPointerException npe) {
        //    }

        //    // get the verbosity flag if specified.
        //    String verbose = daemon.getAttribute("verbose");
        //    if((verbose != null) && (verbose.length() > 0))
        //    this.verbose = (new Boolean(verbose)).booleanValue();

        //    // get the removeClassLoading flag if specified.
        //    String remoteClassLoading =
        //    daemon.getAttribute("remoteClassLoading");
        //    if((remoteClassLoading != null) &&
        //       (remoteClassLoading.length() > 0))
        //    this.remoteClassLoading =
        //        (new Boolean(remoteClassLoading)).booleanValue();

        //    // Get the log file if specified.
        //    this.log = daemon.getAttribute("log");
        //    if((this.log != null) && (this.log.length() == 0))
        //    this.log = null;

        //    // Get the list of allowed hosts.
        //    NodeList allows = daemon.getElementsByTagName("allow");
        //    if(allows != null) {
        //    int numAllow = allows.getLength();
        //    for(int i = 0; i < numAllow; i++) {
        //        Element allow = (Element)allows.item(i);
        //        allowed.addElement(allow.getAttribute("host"));
        //    }
        //    }

        //    // Get the list of denied hosts.
        //    NodeList denys = daemon.getElementsByTagName("deny");
        //    if(denys != null) {
        //    int numDenys = denys.getLength();
        //    for(int i = 0; i < numDenys; i++) {
        //        Element deny = (Element)denys.item(i);
        //        denied.addElement(deny.getAttribute("host"));
        //    }
        //    }

        //    // Get the list of agents
        //    NodeList agents = daemon.getElementsByTagName("agent");
        //    if(agents != null) {
        //    int numAgents = agents.getLength();
        //    for(int i = 0; i < numAgents; i++) {
        //        Element agent = (Element)agents.item(i);
        //        AgentParams params =
        //        new AgentParams(agent.getAttribute("class"));
        //        NodeList props = agent.getElementsByTagName("property");
        //        if(props != null) {
        //        int numProps = props.getLength();
        //        for(int j = 0; j < numProps; j++) {
        //            Element prop = (Element)props.item(j);
        //            params.setValue(prop.getAttribute("name"),
        //                    prop.getAttribute("value"));
        //        }
        //        }
        //        this.agents.addElement(params);
        //    }
        //    }

        //    // Get the list of services
        //    NodeList services = daemon.getElementsByTagName("service");
        //    if(services != null) {
        //    int numServices = services.getLength();
        //    for(int i = 0; i < numServices; i++) {
        //        Element service = (Element)services.item(i);
        //        ServiceParams params =
        //        new ServiceParams(service.getAttribute("class"));
        //        String makePublic = service.getAttribute("public");
        //        if((makePublic != null) && (makePublic.length() > 0))
        //        params.setPublic((new Boolean(makePublic)).
        //                 booleanValue());
        //        NodeList props = service.getElementsByTagName("property");
        //        if(props != null) {
        //        int numProps = props.getLength();
        //        for(int j = 0; j < numProps; j++) {
        //            Element prop = (Element)props.item(j);
        //            params.setValue(prop.getAttribute("name"),
        //                    prop.getAttribute("value"));
        //        }
        //        }
        //        this.services.addElement(params);
        //    }
        //    }
        //}
        //}

        /**
         * Returns the port to use.  If not specified, 0 is returned.
         *
         * @return The port for the Daemon to use.
         */
        public int getPort()
        {
            return port;
        }

        /**
         * Returns the name of the log file to use or null if not specified.
         *
         * @return The name of the log file for the Daemon to use.
         */
        public String getLog()
        {
            return log;
        }

        /**
         * Returns the verbosity flag.
         *
         * @return Whether or not the Daemon should be verbose.
         */
        public bool getVerbose()
        {
            return verbose;
        }

        /**
         * Returns the remote classloading flag.
         *
         * @return Whether or not the Daemon should enable remote class loading.
         */
        public bool getRemoteClassLoading()
        {
            return remoteClassLoading;
        }

        /**
         * Returns the list of allowed hosts as a Vector of Strings.
         *
         * @return The list of allowed hosts.
         */
        //public Vector getAllowed() {
        //synchronized(allowed) {
        //    return (Vector)allowed.clone();
        //}
        //}

        /**
         * Returns the list of denied hosts as a Vector of Strings.
         *
         * @return The list of denied hosts.
         */
        //public Vector getDenied() {
        //synchronized(denied) {
        //    return (Vector)denied.clone();
        //}
        //}

        /**
         * Returns the list of AgentParams that represent the list of agents
         * to start up.
         *
         * @return The list of AgentParams that will be used to start up agents.
         */
        //public Vector getAgents() {
        //synchronized(agents) {
        //    return (Vector)agents.clone();
        //}
        //}

        /**
         * Returns the list of ServiceParams that represent the list of daemon
         * services to start up.
         *
         * @return The list of ServiceParams that will be used to start up
         *         services.
         */
        //public Vector getServices() {
        //synchronized(services) {
        //    return (Vector)services.clone();
        //}
        //}

        /**
         * Returns a copy of the original Document that was used to construct
         * the DaemonConfig.
         *
         * @return The Document that was used ton construct the DaemonConfig.
         */
        //public Document getDoc() {
        //synchronized(doc) {
        //    return (Document)doc.cloneNode(true);
        //}
        //}

        /**
         * Parses an XML file and returns a DaemonConfig representing that
         * file.
         *
         * @param file The XML file to parse.
         * @return The DaemonConfig or null if an error is encountered.
         */
        //public static DaemonConfig parse(String file)
        //{
        //return parse(new File(file));
        //}

        /**
         * Parses an xml file and returns a DaemonConfig representing that
         * file.
         *
         * @param file The XML file to parse.
         * @return The DaemonConfig or null if an error is encountered.
         */
        //public static DaemonConfig parse(File file)
        //{
        ////DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        ////try {
        ////    DocumentBuilder builder = factory.newDocumentBuilder();
        ////    Document        doc     = builder.parse(file);
        ////    return new DaemonConfig(doc);
        ////} catch(ParserConfigurationException pce) {
        ////    pce.printStackTrace();
        ////} catch(SAXException se) {
        ////    se.printStackTrace();
        ////}
        //return null;
        //}
    }
}
